set scheme s2color

** Figure B.1(a) -- Presidential elections

// Comparison with other sources
use "$project_path/data/1_input/elections/IFES/IFES_database", clear
gen IFES = 1
keep Country Year Month Type_Election IFES
tempfile IFES
save `IFES'
use "$project_path/data/1_input/elections/Nohlen/Nohlen_database", clear
gen Nohlen = 1
keep Country Year Month Type_Election Nohlen
tempfile Nohlen
save `Nohlen'
use "$project_path/data/3_cleaned/presidential_elections"
keep if Source!=""
gen our_data = 1
merge 1:1 Country Year Month Type_Election using `IFES', nogen
merge 1:1 Country Year Month Type_Election using `Nohlen', nogen
gen decade = Year-mod(Year,10)
collapse (sum) IFES Nohlen our_data, by(decade)
lab var our_data "Our data"
lab var IFES "IFES"
lab var Nohlen "Nohlen"
graph bar (asis) our_data IFES Nohlen, over(decade, label(angle(forty_five) labsize(large))) graphregion(color(white)) legend(row(1) size(large) region(col(white))) ylabel(,angle(0) labsize(large)) title("Number of elections", size(large) placement(9) span)
graph export "$project_path/output/appendix_figures/Appendix_Figure_B1a1.pdf", as(pdf) name("Graph") replace

// Sources used
use "$project_path/data/3_cleaned/presidential_elections.dta", clear
gen decade = Year-mod(Year,10)
keep decade Source
gen AC = 1 if Source=="AC"
gen IFES = 1 if Source=="IFES"
gen Nohlen = 1 if Source=="Nohlen"
gen PDA = 1 if Source=="PDA"
gen Wikipedia = 1 if Source=="Wiki"
gen other = 1 if Source=="AED" | Source=="EED" | Source=="USA" 
collapse (sum) AC IFES Nohlen PDA Wikipedia other, by(decade)
foreach v in AC IFES Nohlen PDA Wikipedia  {
	lab var `v' "`v'"
}
lab var other "Other"
graph hbar (asis) Wikipedia IFES Nohlen AC PDA other, stack vertical over(decade, label(angle(forty_five) labsize(large))) graphregion(color(white)) legend(row(2) size(large) region(col(white))) ylabel(,angle(0) labsize(large)) title("Number of elections", size(large) placement(9) span)
graph export "$project_path/output/appendix_figures/Appendix_Figure_B1a2.pdf", as(pdf) name("Graph") replace

** Figure B.1(b) -- Parliamentary elections

// Comparison with other sources
use "$project_path/data/2_intermediary/elections/Parliamentary elections/parl_elec_dpi", clear
gen DPI = 1
keep Country Year Month Type_Election DPI
tempfile DPI
save `DPI'
use "$project_path/data/2_intermediary/elections/Parliamentary elections/parl_elec_parlgov", clear
gen PARLGOV = 1
keep Country Year Month Type_Election PARLGOV
tempfile PARLGOV
save `PARLGOV'
use "$project_path/data/1_input/elections/Nohlen_Leg/Nohlen_L_database.dta", clear
gen Nohlen = 1
keep Country Year Month Type_Election Nohlen
tempfile Nohlen
save `Nohlen'
use "$project_path/data/3_cleaned/parliamentary_elections.dta", clear
keep if Source!=""
gen our_data = 1
merge 1:1 Country Year Month Type_Election using `DPI', nogen
merge 1:1 Country Year Month Type_Election using `PARLGOV', nogen
merge 1:1 Country Year Month Type_Election using `Nohlen', nogen
gen decade = Year-mod(Year,10)
collapse (sum) DPI PARLGOV Nohlen our_data, by(decade)
lab var our_data "Our data"
lab var PARLGOV "PARLGOV"
lab var DPI "DPI"
lab var Nohlen "Nohlen"
graph bar (asis) our_data DPI Nohlen PARLGOV, over(decade, label(angle(forty_five) labsize(large))) graphregion(color(white)) legend(row(2) size(large) region(col(white))) ylabel(,angle(0) labsize(large)) title("Number of elections", size(large) placement(9) span)
graph export "$project_path/output/appendix_figures/Appendix_Figure_B1b1.pdf", as(pdf) name("Graph") replace

// Sources used
use "$project_path/data/3_cleaned/parliamentary_elections.dta", clear
gen decade = Year-mod(Year,10)
keep decade Source
gen AC = 1 if Source=="AC_L"
gen AED = 1 if Source=="AED_L"
gen DPI = 1 if Source=="DPI"
gen IPU = 1 if Source=="IPU_L"
gen MP = 1 if Source=="MP"
gen Nohlen = 1 if Source=="Nohlen"
gen PARLGOV = 1 if Source=="PARL"
gen Wikipedia = 1 if Source=="Wiki_L"
gen other = 1 if Source=="EED_L" | Source=="GLOBAL" | Source=="IFES_L" | Source=="PDA_L" 
collapse (sum) AC AED DPI IPU MP Nohlen PARLGOV Wikipedia other, by(decade)
foreach v in AC AED DPI IPU MP Nohlen PARLGOV Wikipedia {
	lab var `v' "`v'"
}
lab var other "Other"
graph hbar (asis) Wikipedia DPI Nohlen PARLGOV AC IPU AED MP other, stack vertical over(decade, label(angle(forty_five) labsize(large))) graphregion(color(white)) legend(row(3) size(large) region(col(white))) ylabel(,angle(0) labsize(large)) title("Number of elections", size(large) placement(9) span)
graph export "$project_path/output/appendix_figures/Appendix_Figure_B1b2.pdf", as(pdf) name("Graph") replace
